<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>集合</h2>
<script>
    class zzSet {
        constructor(){
            this.items = {} //
        }
        add(element){ // 增加
            if(!this.has(element)){
                this.items[element] = element
                return true
            }
            return false
        }
        delete(element){ // 删除
            if(!this.has(element)){
               delete this.items[element]
                return true
            }
            return false
        }
        has(element){ // 有木有
            return element in this.items
        }
        clear(){ // 清空
             this.items = {}
        }
        size(){ // 集合大小
            return Object.keys(this.items).length
        }
        values(){
            return Object.values(this.items)
        }
    }
    let data = new zzSet()
    let arr = [1,2,3,4,4,3,2,5]
    arr.forEach((item,index)=>{
        data.add(item)
    })
    console.log(data.values()) // [1,2,3,4,5]
</script>

</body>
</html>
